Batch verification of model¶
Overview¶
If you develop the Next Design extension, you can implement the function of displaying the error location by inputting the model information, implementing the arbitrary verification process.
In the following, we will add a UI button for model verification using the .NET DLL implementation method, and when that button is pressed, all models will be verified at once and an extension that displays the error location will be created.
-
Overall flow
- Preparing .NET DLL development project
- Manifest extension and extension point definition
- Added ribbon UI icon file
- Implementation of verification processing for all models
Goal image
-
When you open the [Advanced Driving System Software Development] project from the Next Design sample project, the [My Extensions] tab is added to the ribbon and the extension function is enabled.
-
If you click [My Extensions]> [Model Verification]> [Verify] button on the ribbon, all the models are collectively verified according to the following verification rules and the error location is displayed.
Verification rule: The model name must not contain single-byte space characters.
-
To clear the displayed error, click Home> Model> Check Error> Clear Error from the ribbon.
download
-
You can download the complete set of files created as a result of this tutorial from the following link.
Download link: ValidationSample-1.zip
.NET DLL development project preparation¶
To create a new .NET DLL development project in Visual Studio to prepare the extension debug environment, follow the steps below.
- Creating a new project in Visual Studio
- Copy of extension development DLL
- Added reference setting for extension development DLL
This section describes the operation procedure in Visual Studio 2019, but you can also develop in Visual Studio 2017 or later (hereinafter referred to as VS).
The following explanations assume that the installation folder is the default. If it is different, replace it with the actual installation folder.
Default installation folder:
C:\Program Files (x86)\DENSO CREATE\Next Design
Creating a new project in VS¶
To create a new .NET DLL development project, follow these steps:
Operating procedure
- Start VS and click Create New Project from the start page to open the Create New Project wizard.
- Select [Class Library (.NET Framework)] by C# from the project template and click the [Next] button.
- In [New Project Configuration], enter the items as shown in the table below and click the [Create] button.
- This will create a new VS project template for class library development in C#.
- Of the files created as a template, the
Class1.cs
file is not used. Remove it from VS Solution Explorer.
Item | Value |
---|---|
Project name and solution name | ValidationSample |
Location | Any parent folder that contains a set of projects |
Framework | .NET Framework 4.6.2 |
Note
-
The following packages must be installed in advance.
.NET Framework 4.6.2 Developer Pack https://dotnet.microsoft.com/download/visual-studio-sdks
Copy of extension development DLL¶
Follow the steps below to copy the DLL used for Next Design extension development.
Operating procedure
-
Copy the following DLL from the Next Design installation folder into your VS project.
NextDesign.Core.dll
NextDesign.Desktop.dll
Add reference setting of DLL for extension development¶
To add the copied DLL to your VS project's reference settings, follow these steps:
Operating procedure
-
From Solution Explorer in VS, expand the following node:
Solution [ValidationSample]> [ValidationSample]> Reference
-
Right-click the Reference node in the tree and execute the Add Reference command from the context menu to open the Reference Manager dialog.
-
Click the [Reference] button at the bottom right of the [Reference Manager] dialog to open the [Select File to Reference] dialog.
-
Select the following DLL file copied to the VS project and press the [Add] button to return to the [Reference Manager] dialog.
NextDesign.Core.dll
NextDesign.Desktop.dll
-
Confirm that the added DLL file is checked in the list in the [Reference Manager] dialog, and click the [OK] button.
-
This will add the DLLs needed for Next Design extension development under the Reference node in the Solution Explorer in VS.
Automation of debug execution preparation¶
To automate the DLL's debug execution preparation as described in Running and Debugging DLL, follow the steps below.
Operating procedure
-
Open the property of solution [ValidationSample]> [ValidationSample], and copy and paste the following script to the following setting items.
Setting items: [Build event]> [Command line of post-build event]
-
Next, in the same property, set the following path in [Debug]> [Start behavior]> [Start External Program].
C:\Program Files (x86)\DENSO CREATE\Next Design\NextDesign.exe
Command line for post-build event
setlocal
set EXTENSIONS_FOLDER=%LOCALAPPDATA%\DENSO CREATE\Next Design\extensions
set DESTINATION_FOLDER=%EXTENSIONS_FOLDER%\$(ProjectName)
if not exist "%EXTENSIONS_FOLDER%" mkdir "%EXTENSIONS_FOLDER%"
del "$(TargetDir)NextDesign.Core.dll" "$(TargetDir)NextDesign.Desktop.dll" >NUL 2>&1
rd/S/Q "%DESTINATION_FOLDER%" >NUL 2>&1
echo Deploy extension into extensions sub folder: %DESTINATION_FOLDER%
xcopy/S/I/Q/Y "$(TargetDir)*.*" "%DESTINATION_FOLDER%"
xcopy/S/I/Q/Y "$(ProjectDir)resources" "%DESTINATION_FOLDER%\resources"
copy/Y "$(ProjectDir)*.json" "%DESTINATION_FOLDER%"
Definition of extension and extension point by manifest¶
To create a new manifest, create a new text file: manifest.json
as a new item in your VS project and define the following:
- Execution program entry point definition
- Extension life cycle definition
- Specify target profile of extension
- UI extension point definition (ribbon tab group button)
- Command extension point definition
Creating a new manifest file¶
To create a new text file: manifest.json
as a new item in your VS project, do the following:
Operating procedure
- Right-click the VS project from the Solution Explorer in VS and execute the Add> New Item command in the context menu.
- Select [Text File] from the types of items to add, enter
manifest.json
in the [Name] input field, and click the [Add] button. - This will create a new empty
manifest.json
file, which will also appear in Solution Explorer in VS.
Implementation code¶
manifest.json
{
//extension definition
"name": "Validation Sample",
"version": "1.1.0",
"publisher": "DENSO CREATE INC.",
"license": "Conforms to the Next Design License Agreement. Copyright (C) 2019 DENSO CREATE INC. All rights reserved.",
"main": "ValidationSample.dll", //Specify the DLL file name of the build result as an entry point.
"lifecycle": "project", //Specify the project lifecycle as the lifecycle.
"baseprofile": "In-vehicle system software development", //Specify the profile name as the condition of the target project.
//extension point definition
"extensionPoints": {
//ribbon
"ribbon": {
"tabs": [
//Define a ribbon tab to add for the extension.
{
"id": "MyExtensions.MainTab",
"label": "My Extensions",
"orderAfter": "System.Help",
"groups": [
//Define a group that separates the ribbon tabs.
{
"id": "MyExtensions.Validation.Group",
"label": "Model validation",
"controls": [
//Define a verification execution button.
{
"type": "Button",
"id": "MyExtensions.Validation.RunButton",
"label": "verification",
"description": "Validate all models",
"imageLarge": "resources/icon.png",
"command": "Command.Validation.Run" //Specify the id of the validation command defined in the command below.
}
]
}
]
}
]
},
//command
"commands": [
//Define a verification command that calls the verification process command handler `Run`.
{
"id": "Command.Validation.Run",
"execFunc": "Run", //Specifies the public method implemented in the entry point main class.
"canExecWhen": {
"uiState": "ProjectOpened" //Specifies that the project is open as a valid condition for the command.
}
}
],
//event
"events": {
}
}
}
Add icon file for ribbon UI¶
Follow the steps below to add the UI button icon file specified in the imageLarge
of the verification execution button in the manifest above to the VS project.
Operating procedure
- Create a
resources
subfolder directly under your VS project. - Store the
icon.png
file in the created subfolder. (A sample of the icon.png file is included in the download file described in the overview) - If you also want to register the icon file in Solution Explorer of VS, drag and drop the
resources
subfolder onto the VS project of Solution Explorer. (This operation is optional. There is no problem if you do not register the icon file.)
Info
- We recommend 32x32 for large icons and 16x16 for small icons.
Implementation of verification processing for all models¶
To implement the extension entry point and validation process, create a new class: ValidationSample
as a new item in your VS project and implement the following contents.
- Namespace declaration of the referenced API
- Entry point DLL main class
- Command handler for verification processing (public method)
- Extension initialization/termination processing
Creating a new class¶
To create a new class: ValidationSample
as a new item in your VS project, do the following:
Operating procedure
- Right-click the VS project from VS Solution Explorer and execute the Add> Class command from the context menu.
- Make sure that [Class] is selected for the type of item to add, enter
ValidationSample
in the [Name] input field, and click the [Add] button. - This will create a new template for the
ValidationSample.cs
file and it will also appear in the Solution Explorer in VS.
Implementation code¶
ValidationSample.cs
//Declaration of the namespace of the API referenced in extension development
using NextDesign.Extension;
using NextDesign.Core;
using NextDesign.Desktop;
///<summary>
///Main class of the entry point DLL
///</summary>
///<remarks>
///Implement the `IExtension` interface in the main class of the entry point.
///Implement the handler as a public method of this class.
///</remarks>
public class ValidationSample :IExtension
{
///<summary>
///Command handler for verification processing
///</summary>
///<param name="context">command context</param>
///<param name="parameters">command parameters</param>
///<remarks>
///Implement the verification process command handler as a public method of the main class.
///</remarks>
public void Run(ICommandContext context, ICommandParams parameters)
{
var app = context.App;
var project = app.Workspace.CurrentProject;
//Clear all previous errors.
app.Errors.ClearErrors();
//Display the error list window.
app.Window.IsInformationPaneVisible = true;
app.Window.ActiveInfoWindow = "Error";
//Iterate over all the models in the project.
var models = project.GetAllChildren();
foreach (var model in models)
{
//Validate the model according to the validation rules.
ValidateModel(model);
}
}
///<summary>
///Validate model according to validation rules
///</summary>
///<param name="model">model</param>
private void ValidateModel(IModel model)
{
//Match the following validation rules.
//・Do not include spaces in the model name
if (model.Name.IndexOf(" ")> 0)
{
//If it does not meet the validation rules, add error information to the corresponding model.
var message = string.Format("The model name contains spaces. Model name: {0}", model.Name);
var error = model.AddError("Name", "Error", "Model naming convention check", message);
}
}
///<summary>
///Extension initialization
///</summary>
///<param name="context">Execution context</param>
///<remarks>
///Even if you do not need extension initialization/termination processing, empty `Activate` and `Deactivate` methods are required.
///</remarks>
public void Activate(IContext context)
{
//Implement extension initialization etc. if necessary.
}
///<summary>
///Extension end processing
///</summary>
///<param name="context">Execution context</param>
///<remarks>
///Even if you do not need extension initialization/termination processing, empty `Activate` and `Deactivate` methods are required.
///</remarks>
public void Deactivate(IContext context)
{
//Implement extension termination processing etc. if necessary.
}
}